package com.lulufind.lulu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.lulufind.lulu.model.Coterie;
import com.lulufind.lulu.model.CoterieImage;
import com.lulufind.lulu.model.CoterieImageComment;
import com.lulufind.lulu.model.CoterieImageUserPoint;
import com.lulufind.lulu.model.CoterieTemp;
import com.lulufind.lulu.model.Result;
import com.lulufind.lulu.service.CoterieService;
import com.lulufind.lulu.vo.CoterieImageCommentInfoVO;
import com.lulufind.lulu.vo.CoterieImageInfoVO;
import com.lulufind.lulu.vo.CoterieInfoVO;

@Controller
@RequestMapping("/coterie")
public class CoterieController {
	
	@Autowired
	CoterieService coterieService;
	
	@ResponseBody
	@RequestMapping(value="/addCoterieImage",produces="application/json;charset=UTF-8")
	public String addCoterieImage(CoterieImage coterieImage, String userToken){
		
		Result<CoterieImage> rs = coterieService.addCoterieImage(coterieImage, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/delCoterieImage",produces="application/json;charset=UTF-8")
	public String delCoterieImage(Integer imageId, Integer userId, String userToken){
		
		Result<String> rs = coterieService.delCoterieImage(imageId, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/addCoterieImageComment",produces="application/json;charset=UTF-8")
	public String addCoterieImageComment(CoterieImageComment coterieImageComment, String userToken){
		
		Result<CoterieImageComment> rs = coterieService.addCoterieImageComment(coterieImageComment, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCoteries",produces="application/json;charset=UTF-8")
	public String getCoteries(Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieInfoVO>> rs = coterieService.getCoteries(start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/getHotImage",produces="application/json;charset=UTF-8")
	public String getHotImage(Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieImageInfoVO>> rs = coterieService.getHotImage(start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getAntiHotImage",produces="application/json;charset=UTF-8")
	public String getAntiHotImage(Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieImageInfoVO>> rs = coterieService.getAntiHotImage(start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getHotCoterieImage",produces="application/json;charset=UTF-8")
	public String getHotCoterieImage(Integer coterieId, Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieImageInfoVO>> rs = coterieService.getHotCoterieImage(coterieId, start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getAntiHotCoterieImage",produces="application/json;charset=UTF-8")
	public String getAntiHotCoterieImage(Integer coterieId, Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieImageInfoVO>> rs = coterieService.getAntiHotCoterieImage(coterieId, start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCoterieImageByUser",produces="application/json;charset=UTF-8")
	public String getCoterieImageByUser(Integer userId, String userToken, Integer targetUserId, Integer start, Integer num){
		
		Result<List<CoterieImageInfoVO>> rs = coterieService.getCoterieImageByUser(userId, userToken, targetUserId, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/addCoterieUserJoin",produces="application/json;charset=UTF-8")
	public String addCoterieUserJoin(Integer coterieId, Integer userId, String userToken){
		
		Result<String> rs = coterieService.addCoterieUserJoin(coterieId, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/delCoterieUserJoin",produces="application/json;charset=UTF-8")
	public String delCoterieUserJoin(Integer coterieId, Integer userId, String userToken){
		
		Result<String> rs = coterieService.delCoterieUserJoin(coterieId, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/searchCoterie",produces="application/json;charset=UTF-8")
	public String searchCoterie(String coterieName, Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieInfoVO>> rs = coterieService.searchCoterie(coterieName, start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCoteriesByUser",produces="application/json;charset=UTF-8")
	public String getCoteriesByUser(Integer userId, String userToken){
		
		Result<List<Coterie>> rs = coterieService.getCoteriesByUser(userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/coterieImageUserPoint",produces="application/json;charset=UTF-8")
	public String coterieImageUserPoint(CoterieImageUserPoint coterieImageUserPoint, String userToken){
		
		Result<String> rs = coterieService.coterieImageUserPoint(coterieImageUserPoint, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCoterieImageInfo",produces="application/json;charset=UTF-8")
	public String getCoterieImageInfo(Integer imageId, Integer userId){
		
		Result<CoterieImageInfoVO> rs = coterieService.getCoterieImageInfo(imageId, userId);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	
	@ResponseBody
	@RequestMapping(value="/getCoterieImageComments",produces="application/json;charset=UTF-8")
	public String getCoterieImageComments(Integer imageId, Integer start, Integer num){
		
		Result<List<CoterieImageCommentInfoVO>> rs = coterieService.getCoterieImageComments(imageId, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCoterieImageCommentsByUser",produces="application/json;charset=UTF-8")
	public String getCoterieImageCommentsByUser(Integer userId, Integer start, Integer num){
		
		Result<List<CoterieImageCommentInfoVO>> rs = coterieService.getCoterieImageCommentsByUser(userId, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCoterieInfo",produces="application/json;charset=UTF-8")
	public String getCoterieInfo(Integer coterieId, Integer userId, String userToken){
		
		Result<CoterieInfoVO> rs = coterieService.getCoterieInfo(coterieId, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/applyCoterie",produces="application/json;charset=UTF-8")
	public String applyCoterie(CoterieTemp coterieTemp, String userToken){
		
		Result<String> rs = coterieService.applyCoterie(coterieTemp, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getHotCoterie",produces="application/json;charset=UTF-8")
	public String getHotCoterie(Integer start, Integer num, Integer userId, String userToken){
		
		Result<List<CoterieInfoVO>> rs = coterieService.getHotCoterie(start, num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getRandomImage",produces="application/json;charset=UTF-8")
	public String getRandomImage(Integer num, Integer userId, String userToken){
		
		Result<List<CoterieImageInfoVO>> rs = coterieService.getRandomImage(num, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	
}
